<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>个人中心</title>
		<meta name="viewport" content="initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="//cdn.bootcss.com/weui/0.4.3/style/weui.min.css">
		<link rel="stylesheet" href="//cdn.bootcss.com/jquery-weui/0.8.3/css/jquery-weui.min.css">
		<link rel="stylesheet" href="../css/index.css" />
		<style type="text/css">
			body{
				background-color: #E8E8E8 !important;
			}	
			input{
				 -webkit-user-select:none;
				 /*解決在iphone手机下隐藏input光标*/
			}
		</style>
	</head>
	<body id="wode">
		<div class="laststep">
			<div class="qlist">
				<p>请选择</p>
				<span class="active"><input type="hidden" value="1" />我是业主</span>
				<span><input type="hidden" value="2" />我是租户</span>
			</div>
			<div>
				<p>小区</p>
				<input type="text" readonlyunselectable="on" name="job" id="job" readonly value="请选择小区" data-values="" />
				<img class="sj" src="../img/sj.png" />
			</div>
			<div>
				<div class="weui-row">
				  <div class="weui-col-33">
				  	<p>楼栋</p>
				  	<input type="text" readonlyunselectable="on" name="ld" id="ld" readonly value="--" data-values="" />
				  	<img class="sj" src="../img/sj.png" />
				  </div>
				  <div class="weui-col-33">
				  	<p>单元</p>
				  	<input type="text" readonlyunselectable="on" name="dy" id="dy" readonly value="--" data-values="" />
				  	<img class="sj" src="../img/sj.png" />
				  </div>
				  <div class="weui-col-33">
				  	<p>房号</p>
				  	<input type="text" readonlyunselectable="on" name="fh" id="fh" readonly value="--" data-values="1" />
				  	<img class="sj" src="../img/sj.png" />
				  </div>
				</div>
			</div>
			<input type="hidden" value="" id="addressId"/>
			<a href="javascript:;" class="weui_btn weui_btn_primary wc">完成</a>
		</div>
		
		<script src="//cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
		<script src="//cdn.bootcss.com/jquery-weui/0.8.3/js/jquery-weui.min.js"></script>
		<script type="text/javascript" src="../js/basic.js" ></script>
		<script>
			$(".qlist span").click(function(){
				$(this).addClass("active").siblings().removeClass("active")
			})
			$(document).ready(function() {
	      		$("#job").select({
				  title: "选择小区",
				  items: [
				    {
				      title: "江新苑",
				      value: "1",
				    },
				    {
				      title: "青园",
				      value: "2",
				    },
				    {
				      title: "新州花苑",
				      value: "3",
				    },
				    {
				      title: "运新花苑一区",
				      value: "4",
				    },
				    {
				      title: "运新花苑二区",
				      value: "5",
				    },
				    {
				      title: "运新花苑三区",
				      value: "6",
				    },
				    {
				      title: "运新花苑五区",
				      value: "7",
				    },
				    {
				      title: "政新花园",
				      value: "8",
				    },
				    {
				      title: "府新花园东区",
				      value: "9",
				    },
				    {
				      title: "府新花园西区",
				      value: "10"
				    }
				  ],
				  onChange:function(val){
				  	getBuilding(val.values)
				  }
				});				
			})
			var ip_addr = getUrl();	
			//获取幢
			function getBuilding(houseId){
				$.ajax({
						type: 'post',
						dataType: "json",
						url: ip_addr + 'user/getBuilding ',
						data: {
							houseId: houseId
						},
						success: function(data) {
							var result = data.data;
							if(data.code == 0) {
								var item=[];
								for (var i=0;i<result.length;i++) {
									item.push({
										title:(result[i]+"幢"),
										value:result[i]
									})
								}
								$("#ld").select('update',{
								  title: "选择楼栋",
								  items: item,
								  onChange:function(val){
								  	 getBunit(houseId,val.values)
								  }
								});	
							} else {
								
							}
						}
					});
			}
			//获取单元
			function getBunit(houseId,building){
				$.ajax({
						type: 'post',
						dataType: "json",
						url: ip_addr + 'user/getBunit',
						data: {
							houseId: houseId,
							building:building
						},
						success: function(data) {
							var result = data.data;
							if(data.code == 0) {
								var item=[];
								for (var i=0;i<result.length;i++) {
									item.push({
										title:(result[i]),
										value:result[i]
									})
								}
								$("#dy").select('update',{
								  title: "选择单元",
								  items: item,
								  onChange:function(val){
								  	getRoom(houseId,building,val.values)
								  }
								});	
							} else {
								
							}
						}
					});
			}
			//获取房间号
			function getRoom(houseId,building,bunit){
				$.ajax({
						type: 'post',
						dataType: "json",
						url: ip_addr + 'user/getRoom',
						data: {
							houseId: houseId,
							building:building,
							bunit:bunit
						},
						success: function(data) {
							var result = data.data;
							if(data.code == 0) {
								var item=[];
								for (var i=0;i<result.length;i++) {
									item.push({
										title:(result[i].room),
										value:result[i].id
									})
								}
								$("#fh").select('update',{
								  title: "选择房号",
								  items: item,
								  onChange:function(val){
								  	$("#addressId").val(val.values)
								  }
								});	
							} else {
								
							}
						}
					});
			}
			
			
			$(".wc").click(function(){
				var phone = localStorage.getItem("phone");
				var username = localStorage.getItem("username");
				var type = $(".qlist .active input").val();	
				var addressId = $("#addressId").val();
				
				if(phone == '' || phone == null){
					$.toptip('请输入手机号！', 'warning');
				}else if(username == '' || username == null){
					$.toptip('请输入验证码！', 'warning');
				}else if(type == '' || type == null){
					$.toptip('你是业主还是租户？请选择！', 'warning');
				}else if(addressId == '' || addressId == null){
					$.toptip('请选择您的地址！', 'warning');
				}else{
				$.ajax({
						type: 'post',
						dataType: "json",
						url: ip_addr + 'user/addUser',
						data: {
							username: username,
							phone:phone,
							type:type,
							addressId:addressId
						},
						success: function(data) {
							var result = data.data;
							if(data.code == 0) {
								$.alert({
								  title: '温馨提示',
								  text: '恭喜您，注册成功！',
								  onOK: function () {
								    //点击确认
								     window.location.href = 'wode.html';
								  }
								});
							} else {
								$.toast(data.msg, "cancel");
							}
						}
				});
				}

			})
			
		</script>
	</body>
</html>
